function onActionMenuClick(sAction, iObjType, iObjSubType)
{
var iX = 400;
var iY = 200;
var bClose = false;
var bReload = false;
var bResize = true;
var oResult;
var _oId = new Array(crmFormSubmit.crmFormSubmitId.value);
var sIds = crmFormSubmit.crmFormSubmitId.value;
var sPath = prependOrgName("/_grid/cmds/dlg_" + sAction + ".aspx?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=1&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds));
if (!IsNull(iObjSubType))
{
sPath += "&iObjSubType=" + CrmEncodeDecode.CrmUrlEncode(iObjSubType);
}
switch (sAction)
{
case "addquota":		iX = 600;	iY = 425;
sPath += "&uid=" + _oId[0];
oResult = openStdDlg(sPath, _oId, iX, iY, bResize);
if (oResult && !IsNull(window.frames["areaQuotasFrame"]))
{
window.frames["areaQuotasFrame"].document.location.reload();
oResult = false;
}
sPath = null;
break;
case "applyrule":		iX = 400;	iY = 275;	break;
case "assign":			iX = 456;	iY = 260;	bClose = true;	break;
case "actsetrespon":	iX = 456;	iY = 310;	break;
case "changeorg":
iX = 400;	iY = 325;
if (iObjType == SystemUser)
{
bReload = true;
}
else
{
bClose = true;
}
break;
case "changecaptain":	iX = 400;	iY = 225;	bClose = true;	break;
case "changeparent":
iX = 400;	iY = 225;
bReload = true;
break;
case "delete":	iX = 450; iY = 205;


crmForm.detachCloseAlert();
bClose = true;
switch (iObjType)
{
case Account:
oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_delete_account.aspx?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=1&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds)), _oId, 450, 250);
sPath = null;
break;
case Calendar:
sPath += "&sCalendarId=" + crmForm.calendarid.value;
break;
case Contact:
if (!IsOutlookClient())
{
oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_delete_contact.aspx?iObjType=") + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=1&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds), _oId, 450, 250);
}
else
{
if (location.pathname.toLowerCase().indexOf("/home_") != -1)
{
a.grid = sGrid;
a.opener = window;
return openStdDlg(prependOrgName("/_grid/cmds/dlg_delete_contact.aspx?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=1&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds)), _oId, 450, 250, true, true);
}
else
{
oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_delete_contact.aspx?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=1&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds)), _oId, 450, 250);
}
}
sPath = null;
break;
case OpportunityProduct:
case QuoteDetail:
case SalesOrderDetail:
case InvoiceDetail:
var sParentId = "";
var oArg = new Array();
if (!IsNull(window.opener) && !window.opener.closed)
{
oArg[0] = window.opener.parent;
sParentId = oArg[0].crmFormSubmit.crmFormSubmitId.value;
}
else
{
oArg[0] = null;
}
oArg[1] = _oId;
oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_deleteqoiproduct.aspx?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=" + _oId.length + "&sParentId=" + CrmEncodeDecode.CrmUrlEncode(sParentId)), oArg, 450, 205);
sPath = null;
break;
}
break;
case Queue:

oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_delete_queue.aspx?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=1&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds) + ";"), _oId, iX, iY, bResize);
sPath = null;
break;
case "applyrule":

var sRet = openStdDlg(sPath, _oId, iX, iY, bResize);
oResult = (sRet == null);
sPath = null;
break;
case "activate":
case "deactivate":
if (iObjType == Workflow)
{
var iIndex = sPath.indexOf("&iObjSubType=");
if (iIndex>0)
{
sPath = sPath.substring(0,iIndex)+"&iObjSubType=" + GetWorkflowType();
}
}
sPath += "&confirmMode=1";
iY = 250;
iX = 420;
break;
case "deactivatecampactivity":
sPath += "&confirmMode=1";
iY = 260;
iX = 350;
break;
case "role":			iX = 500;	iY = 335;	break;
case "share":			iX = 800;	iY = 480;	break;
case "status":			iX = 456;	iY = 250;	break;
case "webmailmerge":		iX = 600;	iY = 500;
var oArgs = new Object();
oArgs.TotalRecords		= 1;
oArgs.SelectedRecords	= 1;
oArgs.Ids				= sIds;
oArgs.GridXml           = "";
oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_webmailmerge.aspx?objectTypeCode=") + CrmEncodeDecode.CrmUrlEncode(iObjType), oArgs, iX, iY, bResize);
sPath = null;
break;
}
if (sPath != null)
{
oResult = openStdDlg(sPath, _oId, iX, iY, bResize);
}
if (oResult && bClose)
{
try
{
window.opener.auto(iObjType);
}
catch(e)
{}
window.close();
}
else if (oResult && bReload)
{
crmForm.SubmitCrmForm(4, true, true, false);
try
{
window.opener.auto(iObjType);
}
catch(e)
{}
}
return oResult;
}
function changeState(sAction, iObjType, iFormEventId,iObjSubType)
{
if (!crmForm.IsValid())
{
return;
}
var o = onActionMenuClick(sAction, iObjType,iObjSubType);
if (o)
{
var oAcStateCode;
var oAcStatusCode;
if (IsNull(o))
{
o = new Object();
}
oAcStateCode = createHiddenInput("newStateCode", o.iStateCode ? o.iStateCode : "-1");
oAcStatusCode = createHiddenInput("newStatusCode", o.iStatusCode ? o.iStatusCode : "-1");
if (sAction == "deactivatecampactivity")
{
var oAcStartDate;
var oAcEndDate;
if (o.iStartDate != null)
{
oAcStartDate = createHiddenInput("acStartDate", o.iStartDate);
}
else
{
oAcStartDate = "";
}
if (o.iEndDate != null)
{
oAcEndDate = createHiddenInput("acEndDate", o.iEndDate);
}
else
{
oAcEndDate = "";
}
}
if (!crmForm.SubmitCrmForm(iFormEventId, true, true, false))
{

deleteInput(oAcStateCode);
deleteInput(oAcStatusCode);
}
}
}
function assignObject(objType)
{
var ret_val;
var eventCode;
if (objType == Incident)
{
eventCode = 49;
var sId = crmFormSubmit.crmFormSubmitId.value;
ret_val = openStdDlg(prependOrgName("/_grid/cmds/dlg_assignqueue.aspx?iObjType=112&iTotal=1&sQType=1&FromForm=1&uid=" + CrmEncodeDecode.CrmUrlEncode(sId)), new Array(sId), 456, 300);
}
else
{
eventCode = 47;
var url = prependOrgName("/_grid/cmds/dlg_frmassign.aspx");
url += "?pId=" + CrmEncodeDecode.CrmUrlEncode(crmFormSubmit.crmFormSubmitId.value);
url += "&pType=" + CrmEncodeDecode.CrmUrlEncode(crmFormSubmit.crmFormSubmitObjectType.value);
url += "&iObjType=" + CrmEncodeDecode.CrmUrlEncode(objType);
url += "&iTotal=1";
ret_val = openStdDlg(url, document, 456, 260);
}
if (ret_val)
{

if (ret_val.OwnerId)
{
var oOwnerId = createHiddenInput("assignOwnerId", ret_val.OwnerId);
var oOwnerType = createHiddenInput("assignOwnerType", ret_val.OwnerType);

var lookupItem = new LookupControlItem(ret_val.OwnerId, ret_val.OwnerType, ret_val.OwnerName);
var lookupItems = new Array();
lookupItems.push(lookupItem);
crmForm.ownerid.Clear();
crmForm.ownerid.AddItems(lookupItems);
if (!crmForm.SubmitCrmForm(eventCode, true, true, false))
{


deleteInput(oOwnerId);
deleteInput(oOwnerType);
}
}
}
}
function launchOnDemandWorkflowForm(sGrid, iObjType,workflowId)
{
var itemObjectId = workflowId;
var iY = 200;
var	iX = 500;
if (IsNull(workflowId)||workflowId=="")
{
var lookupItems = LookupObjects(null, "single", "OnDemandWorkflow", "4703", "0", null, "membertypecode=" + CrmEncodeDecode.CrmUrlEncode(iObjType), "0");
if (IsNull(lookupItems) ||  lookupItems.items.length == 0)
{
return;
}
itemObjectId = lookupItems.items[0].id;
}
var a = new Array(crmFormSubmit.crmFormSubmitId.value);
var sIds = crmFormSubmit.crmFormSubmitId.value+";";
var oResult = openStdDlg(prependOrgName("/_grid/cmds/dlg_runworkflow.aspx")+"?iObjType=" + CrmEncodeDecode.CrmUrlEncode(iObjType) + "&iTotal=" +
CrmEncodeDecode.CrmUrlEncode(a.length) + "&wfId=" + CrmEncodeDecode.CrmUrlEncode(itemObjectId)+ "&sIds=" + CrmEncodeDecode.CrmUrlEncode(sIds) , a, iX, iY);
oResult = false;
}
function GetWorkflowType()
{
if (document.all.workflowType.options[document.all.workflowType.selectedIndex].value == "1")
{
return 1;
}
else
{
return 3;
}
}
function SendFormShortcut(bIsThroughEmail, sEntityTitle)
{
var sUrl = window.location.href;

if (IsOutlookLaptopClient() && !IsOnline())
{
var path = stripOrgNameWithForce(sUrl.substr(sUrl.indexOf(window.location.pathname)));
sUrl = WEB_APP_URL + path;
}
var sb = new StringBuilder();
sb.Append(sEntityTitle);
sb.Append("\r\n");
sb.Append("<");
sb.Append(sUrl);
sb.Append(">");
if (!bIsThroughEmail)
{
CopyTextToClipboard(sb.ToString(), "", LOCID_COPY_SHORTCUT_ERROR);
}
else
{
OpenEmailForm("", sEntityTitle, sb.ToString());
}
}
